package com.gingko.duominuo.ui.adapter


import android.annotation.SuppressLint
import android.content.Context
import android.view.LayoutInflater
import android.view.ViewGroup
import androidx.core.content.ContextCompat
import androidx.recyclerview.widget.RecyclerView
import com.gingko.duominuo.R

import com.gingko.duominuo.data.model.WorkOrderItemVo
import com.gingko.duominuo.databinding.ItemWorkOrderBinding
import com.gingko.duominuo.utils.singleClick

class WorkOrderAdapter(val context: Context, val data: List<WorkOrderItemVo>) :
    RecyclerView.Adapter<WorkOrderAdapter.WorkOrderHolder>() {
    var callback: Callback? = null

    inner class WorkOrderHolder(private val viewBinding: ItemWorkOrderBinding) :
        RecyclerView.ViewHolder(viewBinding.root) {

        @SuppressLint("SetTextI18n")
        fun bind(workOrderItemVo: WorkOrderItemVo, position: Int) {
//            proj：项目名称
//            task:任务类型
//            app:平台
//            task_count:可领取的任务总数量
//            job_id:获取订单号和审核文案的id
            workOrderItemVo.reviewStatus?.let {
                if (it) {
                    viewBinding.tvStatus.text = "已审核"
                    viewBinding.tvStatus.setTextColor(
                        ContextCompat.getColor(
                            context,
                            R.color.textLink
                        )
                    )
                } else {
                    viewBinding.tvStatus.text = "未审核"
                    viewBinding.tvStatus.setTextColor(
                        ContextCompat.getColor(
                            context,
                            R.color.color_f85c3b
                        )
                    )

                }
            } ?: also {
                viewBinding.tvStatus.text = "未审核"
                viewBinding.tvStatus.setTextColor(
                    ContextCompat.getColor(
                        context,
                        R.color.color_f85c3b
                    )
                )
            }
            viewBinding.tvItemName.text = workOrderItemVo.data?.staff_nickname
            viewBinding.tvAccountInfo.text = workOrderItemVo.data?.staff_account
            viewBinding.root.singleClick(2500) {
                callback?.onClickItem(position)
            }
        }
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): WorkOrderHolder {
        return WorkOrderHolder(
            ItemWorkOrderBinding.inflate(
                LayoutInflater.from(parent.context),
                parent,
                false
            )
        )
    }

    override fun onBindViewHolder(holder: WorkOrderHolder, position: Int) {
        holder.bind(data[position], position)
    }

    override fun getItemCount(): Int {
        return data.size
    }

    interface Callback {
        fun onClickItem(position: Int)
    }
}